Skip to main content
Version: 12.10.0

api-monitoring-metrics

Documentation for api-monitoring-metrics

Overview

The api-monitoring-metrics endpoint is part of the Flask application designed to monitor the availability of various internal and external APIs. The application collects metrics and exposes them in a format compatible with Prometheus.

Components

  1. Flask Application:

    • Endpoint: /api-monitoring-metrics
    • Function: Collects and returns API availability metrics.
  2. Prometheus Client:

    • Libraries Used: prometheus_client for creating and exposing metrics.
    • Metrics: Custom metrics for internal and external API availability.
  3. Environment Variables:

    • API Endpoints: Defined in the environment variables, categorized as internal and external APIs.
  4. Logging:

    • Logging Setup: Uses Python's logging module to log information about API details and availability checks.
  5. Scheduler:

    • Background Scheduler: Uses apscheduler to schedule background tasks.

Key Functions

  1. get_api_endpoints:

    • Retrieves API endpoint details from environment variables.
    • Categorizes endpoints into internal and external APIs.
  2. parse_api_details:

    • Parses the API details from environment variables into a dictionary format.
  3. check_availability:

    • Checks the availability of each API endpoint.
    • Constructs Prometheus-compatible metrics based on the API response status.
  4. api_monitoring_metrics:

    • Flask route that calls check_availability and returns the metrics.

Process Diagram

Here's the process flow of the monitoring setup:

Steps to Implement

  1. Set Up Environment Variables: Ensure all required environment variables are set, either in a .env file or directly in the deployment configuration.
  2. Initialize the Flask Application: Deploy the Flask application using the specified configurations.
  3. Expose Metrics: The /api-monitoring-metrics endpoint exposes the collected metrics for Prometheus to scrape.

Steps to Deployment

Ensure all required environment variables are set.

environment: "prod"

This should be set as "dev"/"ts"/"sapw"/"prod" based on the deployment environment

api configurations

Format of the api:
api_internal_tenant_name_component: "component:component_name, microservice:microservice_name, endpoint:endpoint_link"

All the endpoints should be replaced by the endpoints from corresponding environmnet.

env variable nameendpoint
api_internal_aokplus_OGSOGS API
api_internal_aokplus_CRMCRM api
api_internal_aokplus_BonusPoliciesBonus Policies API
api_internal_aokplus_BonusMeasuresBonus Measures api
api_external_aokplus_AlemdaAlemda API
api_external_aokplus_DocyetDocyet api
api_external_aokplus_WonderpushWonderpush api
api_external_aokplus_DoctorSearchDoctor Search api
api_external_aokplus_MindshineMindshine api
api_external_aokplus_ThryveCRM Thryve